<?php

function verifierMembre($pseudo, $mdp){
	require("../config/connexion_db.config.php");
	$pass_hash = md5($mdp);
	$reponse = $connexion->query("SELECT COUNT(login) AS nbr, id, login, password, lastConnexion FROM admin WHERE login='".$pseudo."' AND password='".$pass_hash."'") or die(print_r($connexion->errorInfo()));
	$donnees = $reponse->fetch();
	if($donnees['nbr'] == 1){
		session_start();
		$_SESSION['id'] = $donnees['id'];
		$_SESSION['login'] = $pseudo;
		$_SESSION['lastConnexion'] = $donnees['lastConnexion'];
		// save current timestamp
		$connexion->exec("UPDATE admin SET lastConnexion = '".time()."' WHERE id = '".$donnees['id']."'") or die(print_r($connexion->errorInfo()));
		echo "<script>self.location = 'index.php'</script>";
	}
	else{
		$msg = 'Vous avez indiqué un nom d’utilisateur incorrect';
		session_start();
		$_SESSION['error'] = $msg;
		header('Location: login.php'); 
	}
}

function checkFromCookie($pseudo, $mdp){

} 


?>